package cc.rengu.redp.bizimpl.upmp.controller;


import cc.rengu.igas.bomp.facade.BompAlipayMchntManageService;
import cc.rengu.igas.bomp.facade.BompMchntManageService;
import cc.rengu.igas.bomp.facade.BompMchntQueryService;
import cc.rengu.igas.bomp.facade.BompThirdMchntEntryService;
import cc.rengu.igas.bomp.facade.bean.ImageInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntBaseInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntImageInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntInfoBean;
import cc.rengu.igas.bomp.facade.request.AlipayActivityApplyConfirmRequest;
import cc.rengu.igas.bomp.facade.request.ImageFileUpDownloadRequest;
import cc.rengu.igas.bomp.facade.request.InstMchntQueryRequest;
import cc.rengu.igas.bomp.facade.request.MchntImageInfoQueryRequest;
import cc.rengu.igas.bomp.facade.response.AlipayActivityApplyViewResponse;
import cc.rengu.igas.bomp.facade.response.MchntBaseInfoQueryResponse;
import cc.rengu.igas.bomp.facade.response.MchntImageInfoQueryResponse;
import cc.rengu.redp.bizimpl.enums.AlpaySpecialImageEnum;
import cc.rengu.redp.bizimpl.enums.BompQueryTypeEnum;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.domain.AlpayMchntInfo;
import cc.rengu.redp.bizimpl.upmp.domain.UpmpOrganization;
import cc.rengu.redp.bizimpl.upmp.service.*;
import cc.rengu.redp.bizimpl.upmp.service.impl.AlpaySpecialFeeService;
import cc.rengu.redp.bizimpl.upmp.vo.ImageInfoVO;
import cc.rengu.redp.bizimpl.upmp.vo.OperationResult;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘玉亮.LL
 */
@Slf4j
@Api(tags = "商户管理:支付宝特殊费率申请")
@RestController
@RequestMapping(value = "/admin/merParam/alpaySpecialFee")
public class AlpaySpecialFeeController extends BaseController {

    @Autowired
    private AlpaySpecialFeeService alpaySpecialFeeService;

    @Autowired
    private IAlpayMchntInfoService bAlpayMchntInfoService;

    @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompThirdMchntEntryService bompThirdMchntEntryService;

    @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompAlipayMchntManageService alipayMchntManageService;

    @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompMchntManageService bompMchntManageService;

    @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompMchntQueryService bompQueryService;

    @Autowired
    private IUpmpSysParamService upmpSysParamService;

    @Autowired
    private IUpmpBMchntBaseInfoService bMchntBaseInfoService;

    @Autowired
    private IUpmpBMchntImageInfoService bMchntImageInfoService;

    @Autowired
    private IUpmpOrganizationService organizationService;



    //@RequiresPermissions("商户管理:支付宝特殊费率申请")
    @GetMapping(value = "/list")

    public  Map<String, Object> findByPage(HttpServletRequest request, QueryRequest page) throws RedpException {
        return getDataTable(alpaySpecialFeeService.findByPage(request,page));
    }

    /**
     * 支付宝商户下拉列表
     */
    @GetMapping(value = "/alpayMchntInfoSelect2")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "q", value = "参数", required = true, dataType = "String")
    })
    public  Map<String, Object> alpayMchntInfoSelect2(HttpServletRequest request) throws RedpException {
        return bAlpayMchntInfoService.alpayMchntInfoSelect2List(request);
    }

    /**
     * 申请页面
     */

    @GetMapping(value = "/edit")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "optFlag", value = "操作标识", required = true, dataType = "String")
    })
    public  Map<String, Object> applyShow(@ModelAttribute("MchntBaseInfoBean") MchntInfoBean entity, Model model, HttpServletRequest request) throws RedpException {
        HashMap<String, Object> result = new HashMap<>();
                // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String optFlag = request.getParameter("optFlag");
        String instId = request.getParameter("instId");
        if (optFlag.equals("apply")) {
            //申请
            String mchntNo = request.getParameter("mchntNo");
            //加载商户基本信息 加载影像信息
            MchntBaseInfoQueryResponse mchntBaseInfoQueryResponse = alpaySpecialFeeService.mchntBaseInfoQuery(mchntNo);
            entity.setMchntNo(mchntBaseInfoQueryResponse.getMchntBaseInfo().getMchntNo());
            entity.setMchntName(mchntBaseInfoQueryResponse.getMchntBaseInfo().getMchntName());
            entity.setSignInstId(mchntBaseInfoQueryResponse.getMchntBaseInfo().getSignInstId());
            UpmpOrganization signOrg = organizationService.getOrgByCode(mchntBaseInfoQueryResponse.getMchntBaseInfo().getSignInstId(), user.getInstId());
            entity.setSignInstName(signOrg.getOrgName());

            AlpayMchntInfo bAlpayMchntInfo = bAlpayMchntInfoService.findOneByMchntNo(mchntNo);
            if (null != bAlpayMchntInfo) {
                entity.setIndustryType(bAlpayMchntInfo.getAlipayCategory());
            }

            MchntImageInfoQueryRequest req = new MchntImageInfoQueryRequest();
            String traceNo = bMchntBaseInfoService.genMerOrder(user.getInstId());
            req.setUserId(user.getId());
            req.setMchntNo(mchntNo);
            MchntImageInfoQueryResponse mchntImageInfoQueryResponse = bMchntImageInfoService.mchntImageInfoQuery(entity.getInstId(),req,bompQueryService,bMchntBaseInfoService.genMerOrder(user.getInstId()), BompQueryTypeEnum.REAL);
            //加载影像信息
            List<ImageInfoVO> imageTypes = alpaySpecialFeeService.getAllImgType();
            alpaySpecialFeeService.bulidPageImg(mchntImageInfoQueryResponse, imageTypes);
           result.put("imgTypes", imageTypes);
            result.put("entity", entity);
        } else if (optFlag.equals("detail")) {
            //查看
            String mchntNo = request.getParameter("mchntNo");
            /*//加载商户基本信息 加载影像信息
            MchntBaseInfoQueryResponse mchntBaseInfoQueryResponse = alpaySpecialFeeService.mchntBaseInfoQuery(mchntNo);
            entity.setMchntNo(mchntBaseInfoQueryResponse.getMchntBaseInfo().getMchntNo());
            entity.setMchntName(mchntBaseInfoQueryResponse.getMchntBaseInfo().getMchntName());
            entity.setSignInstId(mchntBaseInfoQueryResponse.getMchntBaseInfo().getSignInstId());
            UpmpOrganization signOrg = organizationService.getOrgByCode(mchntBaseInfoQueryResponse.getMchntBaseInfo().getSignInstId(), user.getInstId());
            entity.setSignInstName(signOrg.getOrgName());

            AlpayMchntInfo bAlpayMchntInfo = bAlpayMchntInfoService.findOneByMchntNo(mchntNo);
            if (null != bAlpayMchntInfo) {
                entity.setIndustryType(bAlpayMchntInfo.getAlipayCategory());
            }

            MchntImageInfoQueryRequest req = new MchntImageInfoQueryRequest();
            String traceNo = bMchntBaseInfoService.genMerOrder(user.getInstId());
            req.setUserId(user.getId());
            req.setMchntNo(mchntNo);
            MchntImageInfoQueryResponse mchntImageInfoQueryResponse = bMchntImageInfoService.mchntImageInfoQuery(entity.getInstId(),req,bompQueryService,bMchntBaseInfoService.genMerOrder(user.getInstId()), BompQueryTypeEnum.REAL);
            //加载影像信息
            List<ImageInfoVO> imageTypes = alpaySpecialFeeService.getAllImgType();
            alpaySpecialFeeService.bulidPageImg(mchntImageInfoQueryResponse, imageTypes);*/
            List<ImageInfoVO> imageTypes = alpaySpecialFeeService.getAllImgType();
            AlipayActivityApplyViewResponse res = alpaySpecialFeeService.alipayActivityApplyView(request);
            for (ImageInfoVO imageinfovo:imageTypes){
                if(res.getCheckstandImage()!=null&& imageinfovo.getName().equals("checkstandImage")){
                    ImageInfoBean img = res.getCheckstandImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getShopEntranceImage()!=null&& imageinfovo.getName().equals("shopEntranceImage")){
                    ImageInfoBean img = res.getShopEntranceImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getBusinessLicenseImage()!=null&& imageinfovo.getName().equals("businessLicenseImage")){
                    ImageInfoBean img = res.getBusinessLicenseImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getIndoorImage()!=null&& imageinfovo.getName().equals("indoorImage")){
                    ImageInfoBean img = res.getIndoorImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getSettledImage()!=null&& imageinfovo.getName().equals("settledImage")){
                    ImageInfoBean img = res.getSettledImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getInstitutionalOrganizationImage()!=null&& imageinfovo.getName().equals("institutionalOrganizationImage")){
                    ImageInfoBean img = res.getInstitutionalOrganizationImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getCertFaceImage()!=null&& imageinfovo.getName().equals("certFaceImage")){
                    ImageInfoBean img = res.getCertFaceImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getCertBackImage()!=null&& imageinfovo.getName().equals("certBackImage")){
                    ImageInfoBean img = res.getCertBackImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getRunSchoolLicenseImage()!=null&& imageinfovo.getName().equals("runSchoolLicenseImage")){
                    ImageInfoBean img = res.getRunSchoolLicenseImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getBusinessLicenseImage()!=null&& imageinfovo.getName().equals("orgCertImage")){
                    ImageInfoBean img = res.getBusinessLicenseImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getArtifRegistrationImage()!=null&& imageinfovo.getName().equals("artifRegistrationImage")){
                    ImageInfoBean img = res.getArtifRegistrationImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getMedicalInstrumentPracticeLicenseImage()!=null&& imageinfovo.getName().equals("medicalInstrumentPracticeLicenseImage")){
                    ImageInfoBean img = res.getMedicalInstrumentPracticeLicenseImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getChargeSampleImage()!=null&& imageinfovo.getName().equals("chargeSampleImage")){
                    ImageInfoBean img = res.getChargeSampleImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getPrivateNonenterpriseUnitsImage()!=null&& imageinfovo.getName().equals("privateNonenterpriseUnitsImage")){
                    ImageInfoBean img = res.getPrivateNonenterpriseUnitsImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getDiplomaticNoteImage()!=null&& imageinfovo.getName().equals("diplomaticNoteImage")){
                    ImageInfoBean img = res.getDiplomaticNoteImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
                if(res.getCertificateFileImage()!=null&& imageinfovo.getName().equals("certificateFileImage")){
                    ImageInfoBean img = res.getCertificateFileImage();
                    BeanUtils.copyProperties(img,imageinfovo);
                    imageinfovo.setId(img.getId());
                }
            }

            AlpayMchntInfo bAlpayMchntInfo = bAlpayMchntInfoService.findOneByMchntNo(mchntNo);
            if (null != bAlpayMchntInfo) {
               result.put("industryType", bAlpayMchntInfo.getAlipayCategory());
            }

            //加载数据
           result.put("imgTypes", imageTypes);
            result.put("res", res);
        } else if (optFlag.equals("alipay")) {
            //支付宝入驻查询
            String mchntNo = request.getParameter("mchntNo");
            entity.setInstId(instId);

            //加载商户基本信息
            MchntBaseInfoQueryResponse mchntBaseInfoQueryResponse = alpaySpecialFeeService.mchntBaseInfoQuery(mchntNo);
            entity.setMchntNo(mchntBaseInfoQueryResponse.getMchntBaseInfo().getMchntNo());
            entity.setMchntName(mchntBaseInfoQueryResponse.getMchntBaseInfo().getMchntName());
            entity.setSignInstId(mchntBaseInfoQueryResponse.getMchntBaseInfo().getSignInstId());
            UpmpOrganization signOrg = organizationService.getOrgByCode(mchntBaseInfoQueryResponse.getMchntBaseInfo().getSignInstId(), user.getInstId());
            if (null != signOrg) {
                entity.setSignInstName(signOrg.getOrgName());
            }

            AlpayMchntInfo bAlpayMchntInfo = bAlpayMchntInfoService.findOneByMchntNo(mchntNo);
            if (null != bAlpayMchntInfo) {
                entity.setIndustryType(bAlpayMchntInfo.getAlipayCategory());
            }
            //加载数据
            result.put("entity", entity);
            return result;
        }

       result.put("optFlag", optFlag);
       result.put("instId", instId);
        return result;
    }

    /**
     * 提交申请
     */

    @PostMapping(value = "/apply")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult applySave(@ModelAttribute("MchntBaseInfoBean") MchntBaseInfoBean entity, Model model, HttpServletRequest request) throws RedpException, RedpException {
        String instId = request.getParameter("instId");
                // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        CommonUtils.validateUserInst(instId,user);
        MchntImageInfoQueryRequest req = new MchntImageInfoQueryRequest();
        req.setUserId(user.getId());
        req.setMchntNo(entity.getMchntNo());
        //  MchntImageInfoQueryResponse mchntImageInfoQueryResponse = bMchntImageInfoService.mchntImageInfoQuery(instId,req,bompQueryService,bMchntBaseInfoService.genMerOrder(user.getInstId()), BompQueryTypeEnum.REAL);

        return alpaySpecialFeeService.applySave(request);
    }

    /**
     * 根据商户码查询 对应的支付宝特发费率申请的MCC码-支付宝类目
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/queryMcc")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult getMccCode(HttpServletRequest request) {
        Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        String mchntNo = request.getParameter("mchntNo");
        AlpayMchntInfo bAlpayMchntInfo = bAlpayMchntInfoService.findOneByMchntNo(mchntNo);

        //
        result.put("alipayCategory", bAlpayMchntInfo.getAlipayCategory());

        return OperationResult.buildSuccessResult("验证通过", result);
    }

    /**
     * 验证 特殊费率申请标识 特殊费率申请结果
     */
    @PostMapping(value = "/validate")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult validate(HttpServletRequest request) throws RedpException {
                // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        boolean validateFlag = false;
        try {
            validateFlag = alpaySpecialFeeService.validate(request, result);
        } catch (Exception e) {
            result.put("resCode", BusinessContainer.ERROR);
            result.put("resMsg", e.getMessage());
            log.error(e.getMessage());
            return OperationResult.buildFailureResult( "验证 特殊费率申请标识 特殊费率申请结果失败", result);
        }
        if (validateFlag) {
            //加载商户基本信息 加载影像信息
            loadMchntInfo(request, result,user);

            return OperationResult.buildSuccessResult("验证通过", result);
        } else {
            return OperationResult.buildFailureResult("验证失败", result);
        }
    }

    /**
     * 上传影像信息
     */
    @PostMapping(value = "/uploadExitImageToThird")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imgId", value = "图片Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "oprType", value = "操作类型", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imageType", value = "图片类型", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult uploadExitImageToThird(HttpServletRequest request) throws RedpException{
                // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String instId = request.getParameter("instId");
        CommonUtils.validateUserInst(instId,user);
        String mchntNo = request.getParameter("mchntNo");
        String id = request.getParameter("imgId");
        String oprType = request.getParameter("oprType");
        String imageType = request.getParameter("imageType");
        ImageFileUpDownloadRequest req = new ImageFileUpDownloadRequest();
        req.setMchntNo(mchntNo);
        req.setOprType(oprType);
        req.setImageType(imageType);
        req.setId(id);
        req.setUserId(user.getId());
        return bMchntBaseInfoService.imageFileUpDownload(instId,req, bompMchntManageService,bMchntBaseInfoService.genMerOrder(user.getInstId()),null);
    }

    /**
     * 入驻查询
     */
    @PostMapping(value = "/alipayMchntQuery")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult alipayMchntQuery(@ModelAttribute("MchntBaseInfoBean") MchntBaseInfoBean entity, Model model, HttpServletRequest request) {
        //加载支付宝入驻查询接口
        String instId = request.getParameter("instId");
                // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        InstMchntQueryRequest req = new InstMchntQueryRequest();
        req.setMchntNo(entity.getMchntNo());
        req.setChannelFlag("02");
        req.setUserId(user.getId());
        return bMchntBaseInfoService.thirdEntryQuery(instId, req, bMchntBaseInfoService.genMerOrder(user.getInstId()));
    }

    /**
     * 特殊费率申请确认
     */
    @PostMapping(value = "/alipayActivityApplyConfirm")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "activityApplyId", value = "特殊费率申请ID", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult alipayActivityApplyConfirm(@ModelAttribute("alipayActivityApplyConfirmRequest") AlipayActivityApplyConfirmRequest req, Model model, HttpServletRequest request) {
        Map<String, Object> result = com.google.common.collect.Maps.newHashMap();

                // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        if (StringUtils.isBlank(req.getMchntNo())) {
            return OperationResult.buildFailureResult("商户号不可为空", result);
        }
        if (StringUtils.isBlank(req.getActivityApplyId())) {
            return OperationResult.buildFailureResult("特殊费率申请ID不可为空", result);
        }
        String instId = request.getParameter("instId");
        // 调用特殊费率申请确认接口
        req.setUserId(user.getId());
        return alpaySpecialFeeService.alipayActivityApplyConfirm(instId, req, alipayMchntManageService, bMchntBaseInfoService.genMerOrder(user.getInstId()));
    }


    public void loadMchntInfo(HttpServletRequest request, Map<String, Object> result, UpmpUserInfoVO user) throws RedpException {
        //加载商户基本信息
        String mchntNo = request.getParameter("mchntNo");
        String instId = request.getParameter("instId");
        MchntBaseInfoQueryResponse mchntBaseInfoQueryResponse = alpaySpecialFeeService.mchntBaseInfoQuery(mchntNo);
        result.put("mchntBaseInfo", JSON.toJSONString(mchntBaseInfoQueryResponse));
        //加载影像信息
        MchntImageInfoQueryRequest req = new MchntImageInfoQueryRequest();
        String traceNo = bMchntBaseInfoService.genMerOrder(user.getInstId());
        req.setUserId(user.getId());
        req.setMchntNo(mchntNo);
        MchntImageInfoQueryResponse mchntImageInfoQueryResponse = bMchntImageInfoService.mchntImageInfoQuery(instId,req,bompQueryService,bMchntBaseInfoService.genMerOrder(user.getInstId()), BompQueryTypeEnum.REAL);

        List<ImageInfoVO> imageTypes = alpaySpecialFeeService.getAllImgType();
        alpaySpecialFeeService.bulidPageImg(mchntImageInfoQueryResponse, imageTypes);
        result.put("mchntImageInfo", JSON.toJSONString(imageTypes));
    }

    @PostMapping(value = "/imageInfoManage")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "oprType", value = "操作类型 01-商户影像信息新增 02-商户影像信息修改 03-商户影像信息审核", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imageLocalPath", value = "图片本地存储路径", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "alipayImageId", value = "支付宝标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imageName", value = "图片名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "title", value = "图片描述", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult mchntImageInfoManage(HttpServletRequest request) {
        String imageLocalPath = request.getParameter("imageLocalPath");
        String alipayImageId = request.getParameter("alipayImageId");
        String imageName = request.getParameter("imageName");
        String imageType = AlpaySpecialImageEnum.getImageTypeByName(imageName);
        String imageDesc = request.getParameter("title");

        ImageInfoBean imageInfoBean = new ImageInfoBean();
        imageInfoBean.setAlipayImageId(alipayImageId);
        imageInfoBean.setImageIndex("0");
        imageInfoBean.setImageLocalPath(imageLocalPath);
        imageInfoBean.setImageDesc(imageDesc);
        List<ImageInfoBean> imageInfoList = new ArrayList<>();
        imageInfoList.add(imageInfoBean);

        MchntImageInfoBean mchntImageInfoBean = new MchntImageInfoBean();
        mchntImageInfoBean.setImageType(imageType);
        mchntImageInfoBean.setImageInfoList(imageInfoList);
        List<MchntImageInfoBean> imgList = new ArrayList<>();
        imgList.add(mchntImageInfoBean);
        java.util.Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        try {
            alpaySpecialFeeService.mchntImageInfoManage(request, imgList);
        } catch (Exception e) {
            return OperationResult.buildFailureResult("保存影像信息失败",result);
        }
        return OperationResult.buildSuccessResult(result);
    }

    @PostMapping(value = "/updateImageInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "alipayImageId", value = "支付宝影像图片编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imageId", value = "图片编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imageName", value = "图片名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "imageIndex", value = "图片序号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "mchntNo", value = "商户号", required = true, dataType = "String")
    })
    public OperationResult updateMchntImageInfo(HttpServletRequest request) {
        String instId = request.getParameter("instId");
        String mchntNo = request.getParameter("mchntNo");
        String alipayImageId = request.getParameter("alipayImageId");
        String imageName = request.getParameter("imageName");
        String imageType = AlpaySpecialImageEnum.getImageTypeByName(imageName);
        String imageId = request.getParameter("imageId");
        String imageIndex = request.getParameter("imageIndex");
        return alpaySpecialFeeService.updAlipayImageId(instId, mchntNo,imageType, imageIndex, alipayImageId, imageId);
    }
}
